package errMsg

import (
	"fmt"
	"ginblog/config"
	"runtime"
	"strings"
)

func ErrorLog(err error, args ...interface{}) {
	var (
		src string
	)
	if caller, file, line, ok := runtime.Caller(-1); ok {
		file = file[strings.Index(file, "wms_server")+11:]
		funcName := runtime.FuncForPC(caller).Name()
		fn := funcName[strings.LastIndex(funcName, "/")+1:]
		src = fmt.Sprintf("%s:%d %s", file, line, fn)
	}
	if config.RunMode == "release" {
		fmt.Println(src, ":", args, ":", err)
		return
	}
}

func HandleError(err error, args ...interface{}) {
	if err != nil {
		ErrorLog(err, args)
	}
	return
}
